package com.furnitur.modules.portal.controller;

import com.furnitur.common.api.Result;
import com.furnitur.modules.portal.dto.cart.CartAddDTO;
import com.furnitur.modules.portal.service.PortalCartService;
import com.furnitur.modules.portal.vo.cart.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/portal/cart")
public class PortalCartController {

    @Autowired
    private PortalCartService cartService;

    @PostMapping
    public Result<Void> addToCart(@Valid @RequestBody CartAddDTO dto) {
        cartService.addToCart(dto);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<CartVO>> getCartList() {
        return Result.success(cartService.getCartList());
    }

    @PutMapping("/{id}/quantity")
    public Result<Void> updateQuantity(
            @PathVariable("id") Long cartId,
            @RequestParam Integer quantity) {
        cartService.updateQuantity(cartId, quantity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteCartItem(@PathVariable("id") Long cartId) {
        cartService.deleteCartItem(cartId);
        return Result.success();
    }
} 